home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / PRIME13.ZIP / PRIMEDOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  2.0 KB  |  70 lines

  1. /*
  2.         PRIME is (C)opyright 1995 by Paul Damer and Jawed Karim
  3.         You may distribute the source freely only if it remains
  4.         unchanged and is distributed along with prime.doc. You may 
  5.         also recompile it for whatever platform, and give yourself 
  6.         credit by letting it display your name upon startup of 
  7.         PRIME. Leave the authors display lines unchanged however.
  8.  
  9.         Jawed Karim <kari0022@gold.tc.umn.edu>
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <conio.h>
  14. #include <math.h>
  15.  
  16. void main()
  17. {
  18.         double x, y;
  19.         int counter = 0;
  20.         clrscr();
  21.        
  22.         puts("PRIME NUMBER GENERATOR v1.3");
  23.         puts("(C) 1996 by Jawed Karim <Jawed.Karim-1@umn.edu> and Paul Damer");
  24.         puts("--------------------------------------------------------------");
  25.         puts("");
  26.         printf("START: ");
  27.         scanf("%lf", &x);
  28.  
  29.         if ( (x < 0) || ( floor(x) != x ) )
  30.         {
  31.                 puts("ERROR: enter positive integers only.");
  32.                 exit(1);
  33.         }
  34.         
  35.         if (x < 2)
  36.                 printf("2\n3\n"); /* the loop leaves these numbers out.. */
  37.         
  38.         if (x == 2)
  39.                 printf("3\n");
  40.         
  41.         while (1)
  42.         {
  43.                 x++;                
  44.         
  45.                 y = floor ( sqrt ( x ) );
  46.  
  47.         lbl: ;
  48.  
  49.                 if ( ( (x/y)-(floor (x/y)) ) != 0 )
  50.                 {
  51.                         y--;                
  52.                         
  53.                         if ( y<2 )
  54.                         {        
  55.                                 if (counter == 24)
  56.                                 {
  57.                                         gotoxy(1,1);
  58.                                         counter = 0;
  59.                                 }
  60.  
  61.                                 printf("%.0lf\n", x);
  62.                                 counter++;
  63.                         }
  64.                         
  65.                         else
  66.                                 goto lbl;
  67.                 }
  68.         }
  69. }
  70.